const Router = require('koa-router');
const Banner = require('../dbs/models/banner');

const router = new Router({
  prefix: '/banner' //路由前缀
});

// 获取图片列表
router.get('/getList', async (ctx) => {
  const lists = await Banner.find();

  ctx.body = {
    status: 200,
    data: lists
  }
});

router.post('/addBanner', async (ctx) => {
  const banner = new Banner({
    path: ctx.request.body.path,
    title: ctx.request.body.title,
    describe: ctx.request.body.describe
  });
  try {
    await banner.save();
    ctx.body = {
      status: 200,
      msg: '保存成功'
    }
  } catch (e) {
    ctx.body = {
      status: 500,
      msg: '保存失败'
    }
  }

})
module.exports = router;
